#ifndef TOKENIZER_H
#define TOKENIZER_H

#include <vector>
#include <string>
#include <memory>
#include <cstdio>
#include <exception>
#include "../util/NTuple.h"

using namespace std;

namespace dataengine
{
	class DataException;
}

namespace util
{
	/** Tokenizes a file, extracting each space-separated string*/
	class Tokenizer
	{
		protected:
			/** File to read from */
			FILE * m_file;

		public:
			/** Constructor
			  @param filename File to read */
			Tokenizer(string filename);
			/** Gets the file pointer to the beginning of the file */
			void rewind();
			/** Gets the next word in the file */
			string getNextWord();
			/** Reads the next chars in the file as a floating point number */
			float getNextFloat();
			/** Reads the next 3 words as 3 floating point numbers*/
			void readNextFloatTriplet(util::Triplet<float> & result);
			/** Checks if the file pointer is at the end of the file */
			bool eof(){return feof(m_file);}
			/* Destructor */
			~Tokenizer();
			/** Utility function to check if the expected string is the same as the received one */
			void checkToken(string expected, string received);
	};

	/** Class used for tokenizer errors */
	class TokenizerException : public std::exception
	{
		public:
			/**Exception constructor
			  @param __str Message of the exception
			 */
			explicit
				TokenizerException(const std::string __str) throw() : _M_msg(__str){};
			/** Destructor*/
			virtual ~TokenizerException() throw(){};
			/** Returns the exception message */
			virtual const char*	what() const throw(){ return _M_msg.c_str();}

		private:
			std::string _M_msg;
	};

}
#endif
